package com.nohgun.bike.database;


import java.sql.Timestamp;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;





import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;


// 해당 버젼이 틀릴때만 onCreate 생성된다.

public class DBHelper extends SQLiteOpenHelper {
	
	public static final String DB_NAME = "bike";
	public static final int DB_VERSION = 1;
	
	private static final String PASS_INF_CREATE = " CREATE TABLE pass_inf ( "
			+ " pass_id INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL, "
			+ " pass_title TEXT  NULL, "
			+ " time_interval INTEGER  NULL, "
			+ " pass_reg_dt TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL, "
			+ " pass_udt_dt TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL "
			+ " );";
	
	private static final String PASS_INF_INDEX1_CREATE = " CREATE UNIQUE INDEX pass_inf_uix  ON pass_inf ( pass_id  ASC);";

	private static final String COORDINATE_INF_CREATE = " CREATE TABLE coordinate_inf ( "
			+ " pass_id TEXT  INTEGER NOT NULL , "
			+ " coordinate_id INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL, "
			+ " coordinate_value INTEGER  NULL, "
			+ " coordinate_reg_dt TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL, "
			+ " coordinate_udt_dt TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL "
			+ " );";
	
	private static final String COORDINATE_INF_INDEX1_CREATE = " CREATE UNIQUE INDEX coordinate_inf_uix  "
																+" ON coordinate_inf ( coordinate_id  ASC);";
		/*
		private static final String PASS_INF_INDEX2_CREATE = "CREATE INDEX memo_ix2 "
			+ " ON memo ( memo_icon, memo_id );";
		
		private static final String PASS_INF_INDEX3_CREATE = "CREATE INDEX memo_ix3 "
			+ " ON memo ( memo_class_id, memo_id );";
		 */
		
		
	public DBHelper(final Context context) {
        super(context, DBHelper.DB_NAME, null, DBHelper.DB_VERSION);
    }
	@Override
    public void onCreate(SQLiteDatabase db) {
        try {
        	
        	Log.v("verbose  :: ",DBHelper.class.getSimpleName() + " - table creation "); 
            db.execSQL(PASS_INF_CREATE);
            db.execSQL(PASS_INF_INDEX1_CREATE);
            db.execSQL(COORDINATE_INF_CREATE);
            db.execSQL(COORDINATE_INF_INDEX1_CREATE);
            
        } catch (SQLException e) {
        	Log.e("###error### ",DBHelper.class.getSimpleName(), e);
        }
    }

    @Override
    public void onOpen(final SQLiteDatabase db) {
        super.onOpen(db);
    }

    @Override
    public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
    	Log.v("verbose  :: ",DBHelper.class.getSimpleName() + " - TABLE DROP ");
        db.execSQL("DROP TABLE IF EXISTS pass_inf");
        db.execSQL("DROP TABLE IF EXISTS memo_class");
        db.execSQL("DROP TABLE IF EXISTS coordinate_inf");
        onCreate(db);
    }  
	
}
